package com.fgchen.study.thread;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * Created by fgchen on 2017/7/20.
 */
public class CyclicBarrierDemo {

    public static void main(String[] args) throws Exception {

        final CyclicBarrier  barrier = new CyclicBarrier(1);

        for (int i=0; i<10; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        barrier.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (BrokenBarrierException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName());
                }
            }, String.format("subthread_%s", i)).start();
        }

    }

}
